<?php
namespace Admin\Controller;
use Common\Controller\CoreController;
class OrderController extends CoreController {

	public function index(){

		$order=M('Payorder')->where('status=0')->select();
		foreach ($order as $key => $value) {
			$name[$key]=M('HomeUser')->field('username')->where('id='.$value['user_id'])->find();
		}
		//加入用户名
		foreach ($order as $key => $value) {
			foreach ($name as $k => $v) {
				if ($key===$k) {
					$order[$key]['username']=$v['username'];
				}
			}
		}
		//合并订单里出现的-商品
		foreach ($order as $key => $value) {
			$comid[]=M('ComPayorder')->field('com_id')->where('payorder_id='.$value['id'])->select();
		}
		
		foreach ($comid as $key => $value) {
			foreach ($value as $k => $v) {
				$name=M('Commodity')->field('com_name')->where('id='.$v['com_id'])->find();
				$com[$key][$k]['com_name']=$name['com_name'];
			}
		}

		foreach ($com as $key => $value) {
			$str="";
			foreach ($value as $k => $v) {
				$str.=$v['com_name'].'/';
			}
			$str=substr($str,0,strlen($str)-1);
			$com[$key]=$str;
		}
		foreach ($order as $key => $value) {
			foreach ($com as $k => $v) {
				if ($key===$k) {
					$order[$key]['coms']=$v;
				}
			}
		}
		
		// print_r($order);
		$this->assign('del',U('index.php/Admin/Order/del'));
		$this->assign('pay',U('index.php/Admin/Order/payply'));
		$this->assign('now',U('index.php/Admin/Order/index'));
		$this->assign('order',$order);
		$this->display();
	}
	//取消订单
	public function del(){
		
	}
}